/*
 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
#define RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H

#include <memory>
#include <mutex>

#include "transaction/rs_render_service_client.h"
#include "ui/rs_display_node.h"
#include "ui/rs_surface_node.h"

namespace Keels {
namespace Rosen {

class RSC_EXPORT RSInterfaces {
public:
    static RSInterfaces& GetInstance();
    RSInterfaces(const RSInterfaces&) = delete;
    void operator=(const RSInterfaces&) = delete;

    // mirrorId: decide which screen id to mirror, INVALID_SCREEN_ID means do not mirror any screen.
#ifndef ROSEN_CROSS_PLATFORM
    ScreenId CreateVirtualScreen(const std::string& name, uint32_t width, uint32_t height, sptr<Surface> surface,
        ScreenId mirrorId = 0, int flags = 0, std::vector<NodeId> whiteList = {});

    int32_t SetVirtualScreenBlackList(ScreenId id, std::vector<NodeId>& blackListVector);

    int32_t SetVirtualScreenSecurityExemptionList(ScreenId id, const std::vector<NodeId>& securityExemptionList);

    int32_t SetCastScreenEnableSkipWindow(ScreenId id, bool enable);

    int32_t SetVirtualScreenSurface(ScreenId id, sptr<Surface> surface);
#endif

    bool TakeSurfaceCaptureForUI(std::shared_ptr<RSNode> node, std::shared_ptr<SurfaceCaptureCallback> callback,
        float scaleX = 1.f, float scaleY = 1.f, bool isSync = false);

    bool RegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
    bool UnRegisterTypeface(std::shared_ptr<Drawing::Typeface>& typeface);
#ifndef ROSEN_KEELS
    void SetScreenActiveMode(ScreenId id, uint32_t modeId);

    MemoryGraphic GetMemoryGraphic(int pid);

    std::vector<MemoryGraphic> GetMemoryGraphics();
#endif // !ROSEN_KEELS

#ifndef ROSEN_KEELS
    int32_t SetVirtualScreenResolution(ScreenId id, uint32_t width, uint32_t height);
#endif // !ROSEN_KEELS

#ifndef ROSEN_KEELS
    RSVirtualScreenResolution GetVirtualScreenResolution(ScreenId id);

    void MarkPowerOffNeedProcessOneFrame();

    void DisablePowerOffRenderControl(ScreenId id);

    void SetScreenPowerStatus(ScreenId id, ScreenPowerStatus status);

    RSScreenModeInfo GetScreenActiveMode(ScreenId id);
#endif // !ROSEN_KEELS

#ifndef ROSEN_KEELS
    std::vector<RSScreenModeInfo> GetScreenSupportedModes(ScreenId id);

    RSScreenCapability GetScreenCapability(ScreenId id);

    ScreenPowerStatus GetScreenPowerStatus(ScreenId id);

    RSScreenData GetScreenData(ScreenId id);
#endif // !ROSEN_KEELS

    std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(
        const std::string& name, const std::shared_ptr<Keels::AppExecFwk::EventHandler>& looper = nullptr);

    std::shared_ptr<VSyncReceiver> CreateVSyncReceiver(const std::string& name, uint64_t id,
        const std::shared_ptr<Keels::AppExecFwk::EventHandler>& looper = nullptr, NodeId windowNodeId = 0);

#ifdef TP_FEATURE_ENABLE
    void SetTpFeatureConfig(int32_t feature, const char* config);
#endif

private:
    RSInterfaces();
    ~RSInterfaces() noexcept;

    bool TakeSurfaceCaptureForUIWithoutUni(
        NodeId id, std::shared_ptr<SurfaceCaptureCallback> callback, float scaleX, float scaleY);

    std::unique_ptr<RSRenderServiceClient> renderServiceClient_;
};
} // namespace Rosen
} // namespace Keels

#endif // RENDER_SERVICE_CLIENT_CORE_TRANSACTION_RS_INTERFACES_H
